﻿Imports System.Windows.Forms

Public Class frmSelectLayer
    Private GISMap As AxMapWinGIS.AxMap

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Public Sub New(ByVal _GISMap As AxMapWinGIS.AxMap)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        GISMap = _GISMap
    End Sub

    Private Sub frmSelectLayer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        With cboLayer.Items
            .Clear()
            For i As Integer = 0 To GISMap.NumLayers - 1
                Dim sf As MapWinGIS.Shapefile = GetShapeFile(GISMap, i)
                If sf IsNot Nothing AndAlso sf.ShapefileType = MapWinGIS.ShpfileType.SHP_POLYGON Then
                    .Add(GISMap.get_LayerName(GISMap.get_LayerHandle(i)))
                End If
            Next
            If GISMap.NumLayers > 0 Then cboLayer.SelectedIndex = 0
        End With
    End Sub

    Private Sub cboLayer_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboLayer.SelectedIndexChanged
        If cboLayer.SelectedIndex = -1 Then Exit Sub
        With cboField.Items
            .Clear()
            Dim sf As MapWinGIS.Shapefile = GetShapeFile(GISMap, cboLayer.Text)
            For i As Integer = 0 To sf.NumFields - 1
                Dim FieldName As String = sf.Field(i).Name
                .Add(FieldName)
                If FieldName.ToUpper = "STATION_ID" Then cboField.Text = FieldName
            Next
            If cboField.Text = "" And cboField.Items.Count > 0 Then cboField.SelectedIndex = 0
        End With
    End Sub
End Class
